
#ifndef IOVERLAPPAIR_H
#define IOVERLAPPAIR_H

#include <BThing>
#include <BVector>
#include "IAlgorithm.h"
#include "ISpaceTree.h"

namespace BWE
{
	struct BodyProxy : public BThing
	{
		inline BodyProxy(BBody* body, const BSpace& space)
		{
			this->body = body;
			this->space = space;
			this->leaf = 0;
		}
		inline ~BodyProxy()
		{

		}
		BBody*		body;
		BSpace		space;
		SpaceNode*	leaf;
	};

	struct IOverlapPair
	{
		inline IOverlapPair()
		{
			proxy0 = 0;
			proxy1 = 0;
		}
		inline IOverlapPair(BodyProxy* proxy0, BodyProxy* proxy1)
		{
			if (proxy0 < proxy1)
			{
				this->proxy0 = proxy0;
				this->proxy1 = proxy1;
			}
			else
			{
				this->proxy0 = proxy1;
				this->proxy1 = proxy0;
			}
		}

		inline bool operator == (const IOverlapPair& other) const
		{
			return (proxy0 == other.proxy0) && (proxy1 == other.proxy1);
		}
		inline bool operator != (const IOverlapPair& other) const
		{
			return (proxy0 != other.proxy0) || (proxy1 != other.proxy1);
		}
		inline bool operator > (const IOverlapPair& other) const
		{
			if (proxy0 > other.proxy0)
				return true;
			if (proxy0 < other.proxy0)
				return false;
			if (proxy1 > other.proxy1)
				return true;
			return false;
		}
		inline bool operator < (const IOverlapPair& other) const
		{
			if (proxy0 < other.proxy0)
				return true;
			if (proxy0 > other.proxy0)
				return false;
			if (proxy1 < other.proxy1)
				return true;
			return false;
		}

		BodyProxy* proxy0;
		BodyProxy* proxy1;
	};

	typedef BArray<IOverlapPair>	IOverlapPairArray;
}

#endif
